<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/admin/layuimini/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/admin/layuimini/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <label class="layui-form-label required">网站名称</label>
        <div class="layui-input-block">
            <input type="text" name="sitename" lay-verify="required" lay-reqtext="网站域名不能为空" placeholder="请输入网站名称"  value="{$config['sitename']}" class="layui-input">
            <tip>填写自己部署网站的名称。</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">网站域名</label>
        <div class="layui-input-block">
            <input type="text" name="siteurl" lay-verify="required" lay-reqtext="网站域名不能为空" placeholder="请输入网站域名"  value="{$config['siteurl']}" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">网站logo</label>
        <div class="layui-input-block">
            <input type="hidden" name="sitelogo"  value="{$config['sitelogo']}" class="layui-input filepath">
            {if $config['sitelogo']}
                <image src="{$config['sitelogo']}" width="100px" class="showImage"/>
            {else/}
                <image src="" style="display: none;" width="100px" class="showImage"/>
            {/if}
            <button type="button" class="layui-btn" id="test1">
                <i class="layui-icon">&#xe67c;</i>上传网站logo
            </button>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">站点邮箱</label>
        <div class="layui-input-block">
            <input type="text" name="siteemail" lay-verify="required" lay-reqtext="网站域名不能为空" placeholder="请输入网站域名"  value="{$config['siteemail']}" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">网站关键字</label>
        <div class="layui-input-block">
            <textarea name="sitekeywords" class="layui-textarea" placeholder="多个关键词用英文状态 , 号分割">{$config['sitekeywords']}</textarea>
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">网站介绍</label>
        <div class="layui-input-block">
            <textarea name="siteinfo" class="layui-textarea">{$config['siteinfo']}</textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
<script src="/static/admin/layuimini/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form','upload'], function () {
        var form = layui.form,
            layer = layui.layer,
            upload = layui.upload,
            $ = layui.$;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            $.ajax({
                url: "{:url('Config/index')}",
                type: 'post',
                dataType: 'json',
                data:data.field,
                success: function (data) {
                    layer.msg(data.msg);
                    //编辑成功
                    if(data['status']){
                        setTimeout(function(){
                            if(window !== parent.window) parent.window.layer.closeAll();
                        }, 2000)
                    }
                },
                error: function (xhr, textstatus, thrown) {
                    return layer.msg('Status:' + xhr.status + '，' + xhr.statusText + '，请稍后再试！');
                }
            });

            return false;
        });

        //上传网站logo
        var uploadInst = upload.render({
            elem: '#test1' //绑定元素
            ,url: "{:url('/common/upload.Api/uploadImage')}" //上传接口
            ,done: function(res){
                //上传完毕回调
                if(res.code == 200){
                    //图片显示
                    $('.showImage').show();
                    $('.showImage').attr({'src':res.data.fileurl});
                    //赋值
                    $('.filepath').val(res.data.fileurl);
                }else{
                    layer.msg(res.msg);
                }
            }
            ,error: function(){
                //请求异常回调
            }
        });

    });
</script>
</body>
</html>